<%@ page pageEncoding="utf-8" contentType="text/html" %>
<%@ page import="model.*"%>
<%
UserGroup[] system_grouplist = (UserGroup[]) request.getAttribute("system_grouplist[]");
UserGroup[] normal_grouplist = (UserGroup[]) request.getAttribute("normal_grouplist[]");
int[] permissions = UserGroup.getAllPermissions();
%>

<%@ include file="header.tpl.jsp"%>

<script src="./js/edit_usergroup.js" type="text/javascript"></script>
<style type="text/css">
td.name input{line-height:1em;width:90%;text-align:center;margin:0;padding:0;}
td.permissions{cursor:pointer;}
</style>

<div class="box list">
	<h2>用户组列表</h2>
	<table>
		<thead>
			<tr>
				<td rowspan="2">类型</td>
				<td rowspan="2" colspan="2">组ID 组名</td>
				<td colspan="8">权限</td>
				<td rowspan="2">操作</td>
			</tr>
			<tr>
				<td>答题</td>
				<td>添加题目</td>
				<td>编辑题目</td>
				<td>删除题目</td>
				<td>添加试题</td>
				<td>编辑试题</td>
				<td>删除试题</td>
				<td>增删题目类型</td>
			</tr>
		</thead>
		<tbody>
			<tr><td rowspan="<%=system_grouplist.length + 1%>">System Groups</td><td colspan="9" style="display:none"></td></tr>
		<%for(int i = 0; i < system_grouplist.length; i++){%>
		<%UserGroup g = system_grouplist[i]; %>
			<tr>
				<td><%=g.getGroupId()%></td>
				<td class="name"><%=g.getGroupName()%></td>
				<%for(int j = 0; j < permissions.length; j++){%>
				<td<%if(!g.isAdministrator()){%> class="permissions"<%}%>><%=g.hasPermission(permissions[j]) ? "Yes" : "No"%></td>
				<%}%>
				<td>&nbsp;</td>
			</tr>
		<%}%>
			<tr><td id="normal_group_title" rowspan="<%=normal_grouplist.length + 1%>">Normal Groups</td><td colspan="9" style="display:none"></td></tr>
		<%for(int i = 0; i < normal_grouplist.length; i++){%>
		<%UserGroup g = normal_grouplist[i]; %>
			<tr>
				<td><%= g.getGroupName() != null ? g.getGroupId() : ""%></td>
				<td class="name"><%=g.getGroupName()%></td>
				<%for(int j = 0; j < permissions.length; j++){%>
				<td class="permissions"><%=g.hasPermission(permissions[j]) ? "Yes" : "No"%></td>
				<%}%>
				<td>
					<a href="###" onclick="duplicateNode(this);$('#normal_group_title').attr('rowspan', parseInt($('#normal_group_title').attr('rowspan')) + 1);initevents();">[+]</a>
					<a href="###" onclick="removeNode(this);$('#normal_group_title').attr('rowspan', parseInt($('#normal_group_title').attr('rowspan')) - 1);initevents();">[-]</a>
				</td>
			</tr>
		<%}%>
		</tbody>
	</table>
</div>

<div class="post_buttons">
	<button id="submit_usergroups">保存配置</button>
</div>

<%@ include file="footer.tpl.jsp"%>